package filter

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 过滤器：保留成交额放量的股票
type TurnoverSurgeFilter struct {
	db *gorm.DB
}

// 初始化
func (t *TurnoverSurgeFilter) Init(db *gorm.DB) {
	t.db = db
}

// 执行
func (t *TurnoverSurgeFilter) DoFilter(transactionDate string) {
	io.Infoln("过滤器：保留成交额放量的股票，交易日期[%s]", transactionDate)
	t.db.Exec("delete from quant_stock_filter q where q.stock_code not in ("+
		"select distinct stda.code_ from stock_transaction_data_all stda "+
		"join quant_stock_filter t on t.stock_code=stda.code_ "+
		"where stda.turnover > (stda.turnover_ma250 * ?) and stda.date_ = to_date(?, 'yyyy-mm-dd'))",
		properties.QuantProperties_.TurnoverSurge, transactionDate)
}
